(async ()=>{
    //
    const mysql = require('mysql2/promise')
    // 连接配置
    const cfg = {
        host:'localhost',
        user:'root',
        password:'asd13579',
        database:'kaikeba'
    }
    const connection = await mysql.createConnection(cfg)
    console.log('连接成功')

    //创建一张表
    const CREATE_SQL = `CREATE TABLE IF NOT EXISTS test(
        id INT NOT NULL AUTO_INCREMENT,
        message VARCHAR(45) NULL,
        PRIMARY KEY (id))`;
    let ret = await connection.execute(CREATE_SQL)
    console.log('create:',ret)

    const INSERT_SQL = `INSERT INTO test(message) VALUES(?)`
    ret = await connection.execute(INSERT_SQL,['abc'])
    console.log('insert:',ret)

    const SELECT_SQL = `SELECT * FROM test`
    const [rows,fields] = await connection.execute(SELECT_SQL)
    console.log('rows',JSON.stringify(rows))
})()